package com.hui.dao;

import com.hui.entity.Category;
import com.hui.mapper.CategoryMapper;
import com.hui.util.DruidUtil;

import java.util.List;

/**
 * @Description 分类持久层
 * @date 2023/2/10 19:43
 */
public class CategoryDao {


    /**
     * 查询全部分类数据
     **/
    public List<Category> findCategoryAll() {
        String sql = "select  * from tb_category ";
        return DruidUtil.commonFindListByParam(sql, new CategoryMapper());
    }

    /**
     * 添加分类数据
     **/
    public void insertCategory(Category category ) {
        String sql = "insert into tb_category values(null,?,?)";
        DruidUtil.commonUpdate(sql, category.getCategoryName(),category.getStatus());
    }

    /**
     * 根据分类的Id修改分类数据
     **/
    public void updateCategoryById(Category category) {
        String sql = "update  tb_category set categoryName=?  where categoryId=? ";
        DruidUtil.commonUpdate(sql, category.getCategoryName(), category.getCategoryId());
    }

    /**
     * 根据Id查询分类的数据
     **/
    public Category findCategoryById(int categoryId) {
        String sql = "select  * from tb_category where   categoryId=?";
        return DruidUtil.commonFindObjectByParam(sql, new CategoryMapper(), categoryId);
    }

    /**
     * 根据Id删除分类的数据
     **/
    public void delCategoryById(int categoryId) {
        String sql = "delete from tb_category where  categoryId=?";
        DruidUtil.commonUpdate(sql, categoryId);
    }


}
